//
//  DiaryDetailViewController.m
//  PSYWeiBo
//
//  Created by xiaotian on 16/3/17.
//  Copyright © 2016年 郑亚田. All rights reserved.
//

#import "DiaryDetailViewController.h"
#import "DiaryDetaiImgView.h"
#import "DiaryEditViewController.h"

@interface DiaryDetailViewController ()<UIActionSheetDelegate>

@end

@implementation DiaryDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.titleLab.text = @"日记详情";
    
    [self setViews];
}

- (void)setViews {
    self.detailImgV = [[DiaryDetaiImgView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
    [self.view addSubview:self.detailImgV];
    [self.detailImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headerImgV.mas_bottom);
        make.left.right.bottom.equalTo(@0);
    }];
    
    [self.editBtn setTitle:@"编辑" forState:UIControlStateNormal];
    [self.editBtn addTarget:self action:@selector(editBtnClick:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)editBtnClick:(UIButton *)sender {
    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"请选择" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"删除日记" otherButtonTitles:@"修改日记", nil];
    [sheet showInView:self.view];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 2) {
        //取消
        return;
    }else if (buttonIndex == 0) {
        //删除日记
        UIAlertController *alert=[UIAlertController alertControllerWithTitle:@"提示" message:@"你确定要删除这篇日记吗？" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {//只能有一个
            return;
        }];
        UIAlertAction *delete = [UIAlertAction actionWithTitle:@"删除日记" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {//红色
            return ;
        }];
        [alert addAction:cancelAction];
        [alert addAction:delete];
        cancelAction = alert.actions.firstObject;
        [self presentViewController:alert animated:YES completion:nil];
    }else {
        //修改日记
//        self.detailImgV.userInteractionEnabled = YES;
        DiaryEditViewController *diaryEdit = [[DiaryEditViewController  alloc] init];
        diaryEdit.modalTransitionStyle = 2;
        [self presentViewController:diaryEdit animated:YES completion:nil];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
